package com.vf.admin.client.dao;

import com.vf.admin.common.db.BaseDao;
import com.vf.admin.miaodong.entity.AppBeckoning;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;

@Repository
public class AppBeckoningDao extends BaseDao<AppBeckoning> {


    public AppBeckoning findBeckoningByUserId(Integer userId, Integer beiUserId) {
        ArrayList<Object> paramList = new ArrayList<>();
        String sql = "select * from app_beckoning where userId=? and beiUserId=? limit 1";
        paramList.add(userId);
        paramList.add(beiUserId);
        return this.queryObj(sql, paramList, AppBeckoning.class);
    }

    public AppBeckoning getLimitOne(Integer userId, Integer beiUserId) {
        ArrayList<Object> paramList = new ArrayList<>();
        String sql = "select * from app_beckoning where (userId=? and beiUserId=?) or (userId=? and beiUserId=?) limit 1";
        paramList.add(userId);
        paramList.add(beiUserId);
        paramList.add(beiUserId);
        paramList.add(userId);
        return this.queryObj(sql, paramList, AppBeckoning.class);
    }


    public void updateBeckoningMutual(Integer userId, Integer beiUserId) {
        ArrayList<Object> paramList = new ArrayList<>();
        String sql = "update app_beckoning set isMutual=1 where (userId=? and beiUserId=?) or (userId=? and beiUserId=?) and isMutual=2";
        paramList.add(userId);
        paramList.add(beiUserId);
        paramList.add(beiUserId);
        paramList.add(userId);
        this.update(sql, paramList);
    }


}
